package com.sheyu;

/**
 * @author sheyu
 * @date 2020/8/25 3:10 下午
 */
public class Index_66 {

    public  int[] plusOne(int[] digits) {
        int cur = 0;
        int digitsLength = digits.length;
        int [] digitsNew = new int[digitsLength+1];
        int addValue = cur+1+digits[digitsLength-1];
        digitsNew[digitsLength] = addValue%10;
        cur = addValue>=10?1:0;
        for (int i = digitsLength-2; i >=0 ; i--) {
            if (cur+digits[i]>=10){
                digitsNew[i+1] = (cur+digits[i])%10;
                cur = 1;
            }else{
                digitsNew[i+1] = digits[i]+cur;
                cur = 0;
            }
        }
        if (cur>0){
            digitsNew[0] = 1;
            return digitsNew;
        }else{
            System.arraycopy(digitsNew,1,digits,0,digitsLength);
            return digits;
        }
    }
}
